package com.wangjie.simple;

import java.util.Stack;

/**
 * @author jieshao
 * @date 2022/8/2 14:14
 *
 * 输入一行字符串，由大小写英文字母、半角空格、英文逗号(,)、英文句号(.)55个字符组成，对每个单词进行反转，并且将大写字母转化为小写字母，小写字母转化为大写字母。
 */
public class Test20 {
    public static void main(String[] args) {
        String s = "I am Kiding, How are you";
        StringBuffer sb = new StringBuffer();
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c != ' ' && c != ',' && c != '.') {
                if (Character.isLowerCase(c)) {
                    c = Character.toUpperCase(c);
                } else {
                    c = Character.toLowerCase(c);
                }
                stack.push(c);
                continue;
            }
            while (!stack.isEmpty()) {
                sb.append(stack.pop());
            }
            sb.append(c);
        }
        while (!stack.isEmpty()) {
            sb.append(stack.pop());
        }
        System.out.println(sb.toString());
    }
}